import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import Cookies from "js-cookie";

// ElementPlus
import ElementPlus from "element-plus";
import "element-plus/dist/index.css";
import * as ElementPlusIconsVue from "@element-plus/icons-vue";
import locale from "element-plus/lib/locale/lang/zh-cn";
// css样式
import "normalize.css/normalize.css";
import "nprogress/nprogress.css";
import "@/assets/styles/index.scss";
// 路由控制
import "./router/interceptor";
// 全局方法
import { resetForm, addTimeRange, handleTree } from "@/utils/common";
import { parseTime } from "@/utils/dateUtil";
// 分页组件
import Pagination from "@/components/Pagination";
// 自定义表格工具组件
import RightToolbar from "@/components/RightToolbar";

const app = createApp(App);

// 全局方法挂载
app.config.globalProperties.parseTime = parseTime;
app.config.globalProperties.resetForm = resetForm;
app.config.globalProperties.handleTree = handleTree;
app.config.globalProperties.addTimeRange = addTimeRange;

// 全局组件挂载
app.component("RightToolbar", RightToolbar);
app.component("Pagination", Pagination);

app
  .use(router)
  .use(store)
  .use(ElementPlus, {
    locale,
    // 支持 large、default、small
    size: Cookies.get("layoutSize") || "default",
  });

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}

app.mount("#app");
